package com.work.game.volley.httpUtil;




import com.work.game.volley.attribute.AUAttributeUtils;
import com.work.game.volley.httpUtil.interfase.HUCParameInterfase;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public final class HCUParame extends HUCBase implements HUCParameInterfase {
    private static HCUParame commonParame;

    /**
     * 构建网络请求参数工具类
     *
     * @return
     */
    public static HCUParame getInstance() {
        if (commonParame == null) {
            commonParame = new HCUParame();
        }
        return commonParame;
    }

    private HCUParame() {
        super();
    }

    public Map<String, String> getRequestParameter(Object objectData) {
        Map<String, String> mapParam = new HashMap<String, String>();
        List<String> thisAttr = AUAttributeUtils.getInstance().getAttributeName(
                objectData.getClass(), false);
        for (int j = 0; j < thisAttr.size(); j++) {
            String setName = thisAttr.get(j);
            String key = setName;
            setName = "get" + setName.substring(0, 1).toUpperCase()
                    + setName.substring(1);
            Method method;
            try {
                method = objectData.getClass().getDeclaredMethod(setName);
                method.setAccessible(true);
                String value = (String) method.invoke(objectData);
                if (value != null && value.length() > 0) {
                    mapParam.put(key, value);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return mapParam;
    }
}
